package com.health.controller.member;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.constant.MessageConstant;
import com.health.entity.PageResult;
import com.health.entity.QueryPageBean;
import com.health.entity.Result;
import com.health.pojo.Member;
import com.health.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname MemberController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2023/3/18 20:31
 * @Author RainGrd
 */
@RestController
@Slf4j
@RequestMapping("/member")
public class MemberController {

    @Reference
    private MemberService memberService;


    @RequestMapping("/findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        log.info("queryPageBean:{}", queryPageBean);
        return memberService.queryMemberPage(queryPageBean);
    }

    @RequestMapping("/add.do")
    //新增会员
    public Result add(@RequestBody Member member) {
        return memberService.saveMember(member);
    }


    @RequestMapping("/edit.do")
    //新增会员
    public Result edit(@RequestBody Member member) {
        log.info("要修改的会员对象:{}", member);
        try {
            int i = memberService.editMember(member);
            return i > 0 ? Result.success(MessageConstant.EDIT_MEMBER_SUCCESS) : Result.error(MessageConstant.EDIT_MEMBER_FAIL);
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.error(MessageConstant.EDIT_MEMBER_FAIL);//新增失败
        }

    }

    @RequestMapping("/delete.do")
    //新增会员
    public Result delete(Integer id) {
        return memberService.deleteMemberById(id);

    }


}
